const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('Sub_comments', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true
    },
    postid: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: "文章id"
    },
    userid: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: "子评论人id"
    },
    reviewers_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      comment: "父评论id",
      references: {
        model: 'parent_comments',
        key: 'id'
      }
    },
    content: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "子评论内容"
    },
    like: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "子评论点赞量"
    },
    send_to: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "空为对评论发起者，传uid,则是对子评论其他用户进行回复"
    }
  }, {
    sequelize,
    tableName: 'Sub_comments',
    timestamps: true,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
      {
        name: "coms",
        using: "BTREE",
        fields: [
          { name: "reviewers_id" },
        ]
      },
    ]
  });
};
